﻿$("#ctl00_ContentPlaceHolder1_drpSheng").change(function () {
    $('#SearchDIV').block({ message: '<img alt="加载中" src="/images/Loading/Uploader.gif" />', css: { border: 'none', backgroundColor: 'transparent'} });
    var drpCity = $("#drpCity");
    var drpRegin = $("#drpRegin");
    drpCity.html('');
    drpCity.append("<option value='0' selected='selected'>请选择</option>");
    drpRegin.html('');
    drpRegin.append("<option value='0' selected='selected'>请选择</option>");
    $.getJSON("PSDZ.aspx", { Check: "GetCity", ProID: $(this).val() }, function (result) {
        $('#SearchDIV').unblock();
        $.each(result, function (i, field) {
            drpCity.append("<option value=\"" + field.value + "\" >" + field.text + "</option>");
        });
    });

});
$("#ctl00_ContentPlaceHolder1_drpAddProv").change(function () {
    $('#AddPSDZDIV').block({ message: '<img alt="加载中" src="/images/Loading/Uploader.gif" />', css: { border: 'none', backgroundColor: 'transparent'} });
    var drpAddCity = $("#ctl00_ContentPlaceHolder1_drpAddCity");
    var drpAddRegion = $("#ctl00_ContentPlaceHolder1_drpAddRegion");
    $.getJSON("PSDZ.aspx", { Check: "GetCity", ProID: $(this).val() }, function (result) {
        drpAddCity.html('');
        $.each(result, function (i, field) {
            drpAddCity.append("<option value=\"" + field.value + "\" >" + field.text + "</option>");
        });
        $.getJSON("PSDZ.aspx", { Check: "GetRegion", CityID: $("#ctl00_ContentPlaceHolder1_drpAddCity").val() }, function (result) {
            $('#AddPSDZDIV').unblock();
            drpAddRegion.html('');
            $.each(result, function (i, field) {
                drpAddRegion.append("<option value=\"" + field.value + "\" >" + field.text + "</option>");
            });
        });
    });
});

$("#drpCity").change(function () {
    $('#SearchDIV').block({ message: '<img alt="登入中" src="/images/Loading/Uploader.gif" />', css: { border: 'none', backgroundColor: 'transparent'} });
    var drpRegin = $("#drpRegin");
    drpRegin.html('');
    drpRegin.append("<option value='0' selected='selected'>请选择</option>");
    $.getJSON("PSDZ.aspx", { Check: "GetRegion", CityID: $(this).val() }, function (result) {
        $('#SearchDIV').unblock();
        $.each(result, function (i, field) {
            drpRegin.append("<option value=\"" + field.value + "\" >" + field.text + "</option>");
        });
    });
});

$("#ctl00_ContentPlaceHolder1_drpAddCity").change(function () {
    $('#AddPSDZDIV').block({ message: '<img alt="加载中" src="/images/Loading/Uploader.gif" />', css: { border: 'none', backgroundColor: 'transparent'} });
    var drpAddRegion = $("#ctl00_ContentPlaceHolder1_drpAddRegion");
    drpAddRegion.html('');
    $.getJSON("PSDZ.aspx", { Check: "GetRegion", CityID: $(this).val() }, function (result) {
        $('#AddPSDZDIV').unblock();
        $.each(result, function (i, field) {
            drpAddRegion.append("<option value=\"" + field.value + "\" >" + field.text + "</option>");
        });
    });

});
$("#add").click(function () {
    $('#AddPSDZDIV').show();
    $('#AddPSDZDIV').dialog({
        title: '添加/修改个人报名信息',
        width: 600,
        height: 500,
        closed: false,
        cache: false,
        modal: true
    });
    $("#AddPSDZDIV").dialog('open');

});
var v = new Validator();

$("#txtAddCompanyName").focus(function () {
    $("#AddCompanyNameNote").removeClass("error").removeClass("success").addClass("note");
    $("#AddCompanyNameNote").html("<span>&nbsp;</span>请输入企业名称");
}).blur(function () {
    if (!$.trim($(this).val())) {
        $("#AddCompanyNameNote").removeClass("note").removeClass("success").addClass("error");
        $("#AddCompanyNameNote").html("<span>&nbsp;</span>请输入企业名称");
    }
});

$("#txtAddUserName").focus(function () {
    $("#UserNameNote").removeClass("error").removeClass("success").addClass("note");
    $("#UserNameNote").html("<span>&nbsp;</span>请输入学员姓名");
}).blur(function () {
    if (!$.trim($(this).val())) {
        $("#UserNameNote").removeClass("note").removeClass("success").addClass("error");
        $("#UserNameNote").html("<span>&nbsp;</span>请输入学员姓名");
    }
});

$("#txtPhone").focus(function () {
    $("#SJNote").removeClass("error").removeClass("success").addClass("note");
    $("#SJNote").html("<span>&nbsp;</span>格式：15387915550-目前只支持国内手机");
}).blur(function () {
    var msg = v.checkMobile("txtPhone", true, msg);
    if (msg) {
        if (msg == true) {
            $("#SJNote").removeClass("note").removeClass("error").addClass("success");
            $("#SJNote").html("<span>&nbsp;</span>输入正确");

        } else {
            $("#SJNote").removeClass("note").removeClass("success").addClass("error");
            $("#SJNote").html("<span>&nbsp;</span>" + msg);
        }
    } else {
        $("#SJNote").removeClass("note").removeClass("success").addClass("error");
        $("#SJNote").html("<span>&nbsp;</span>您输入的手机格式不正确");
    }
});
$("#txtTelphone").focus(function () {
    $("#GDDHNote").removeClass("error").removeClass("success").addClass("note");
    $("#GDDHNote").html("<span>&nbsp;</span>格式：0791-65565597");
}).blur(function () {
    if (!$.trim($(this).val()))
        return;
    var msg = v.checkTel("txtTelphone", false, msg);
    if (msg) {
        if (msg == true) {
            $("#GDDHNote").removeClass("note").removeClass("error").addClass("success");
            $("#GDDHNote").html("<span>&nbsp;</span>输入正确");

        } else {
            $("#GDDHNote").removeClass("note").removeClass("success").addClass("error");
            $("#GDDHNote").html("<span>&nbsp;</span>" + msg);
        }
    } else {
        $("#GDDHNote").removeClass("note").removeClass("success").addClass("error");
        $("#GDDHNote").html("<span>&nbsp;</span>您输入的固定电话格式不正确");
    }
});
$("#txtAddress").focus(function () {
    $("#AddressNote").removeClass("error").removeClass("success").addClass("note");
    $("#AddressNote").html("<span>&nbsp;</span>请输入详细地址");
}).blur(function () {
    if (!$.trim($(this).val())) {
        $("#AddressNote").removeClass("note").removeClass("success").addClass("error");
        $("#AddressNote").html("<span>&nbsp;</span>请输入详细地址");
    }
});

$("#txtCode").focus(function () {
    $("#CodeNote").removeClass("error").removeClass("success").addClass("note");
    $("#CodeNote").html("<span>&nbsp;</span>请输入邮箱");
}).blur(function () {
    var msg = v.checkEmail("txtCode", true, msg);
    if (msg) {
        if (msg == true) {
            $("#CodeNote").removeClass("note").removeClass("error").addClass("success");
            $("#CodeNote").html("<span>&nbsp;</span>输入正确");

        } else {
            $("#CodeNote").removeClass("note").removeClass("success").addClass("error");
            $("#CodeNote").html("<span>&nbsp;</span>" + msg);
        }
    } else {
        $("#CodeNote").removeClass("note").removeClass("success").addClass("error");
        $("#CodeNote").html("<span>&nbsp;</span>您输入的邮箱格式不正确");
    }
});

$("#AddZXFS").click(function () {
    var AddHtml = $(".ZXLXFS").html();
    $("#ZXLXFSTD").append('<div class="ZXLXFS">' + AddHtml + '</div><span class="colf2 DelZXLXFS" style="display: block; padding-top:2px; cursor: pointer">删除</span>');
});
$(".DelZXLXFS").live("click", function () {
    $(this).prev().remove();
    $(this).remove();
});
$("#ZXLXFSTD .GRZXInput").live("focus", function () {
    var nextSpan = $(this).next();
    nextSpan.removeClass("error").removeClass("success").addClass("note");
    nextSpan.html("<span>&nbsp;</span>请输入在线联系方式");
}).live("blur", function () {
    if (!$.trim($(this).val())) {
        var nextSpan = $(this).next();
        nextSpan.removeClass("note").removeClass("success").addClass("error");
        nextSpan.html("<span>&nbsp;</span>请输入在线联系方式");
    }
});

$("#AddPSDZ").click(function () {
    var lblCount = $("#ctl00_ContentPlaceHolder1_lblCount");
    if (lblCount.text() == "10") {
        alert('您最多只能添加10个');
        return;
    }

    var AddCompanyName = $("#txtAddCompanyName");
    if (AddCompanyName[0]) {
        AddCompanyName = AddCompanyName.val()
        if (!$.trim(AddCompanyName)) {
            alert("请输入企业名称");
            return;
        }
    }
    else
        AddCompanyName = "";

    var AddUserName = $("#txtAddUserName").val();
    if (!$.trim(AddUserName)) {
        alert("请输入学员姓名");
        return;
    }

    var msg = v.checkMobile("txtPhone", true, msg);
    if (msg) {
        if (msg != true) {
            alert(msg);
            return;
        }
    } else {
        alert("您输入的手机格式不正确");
        return;
    }
    var AddPhone = $("#txtPhone").val();
    var AddTelPhone = $("#txtTelphone").val();
    if ($.trim(AddTelPhone)) {
        msg = v.checkTel("txtTelphone", false, msg);
        if (msg) {
            if (msg != true) {
                alert(msg);
                return;
            }
        } else {
            alert("您输入的固定电话格式不正确");
            return;
        }
    }
    var AddAddress = $("#txtAddress").val();
    if (!$.trim(AddAddress)) {
        alert("请输入详细地址");
        return;
    }
    msg = v.checkEmail("txtCode", true, msg);
    if (msg) {
        if (msg != true) {
            alert(msg);
            return;
        }
    } else {
        alert("您输入的邮箱不正确");
        return;
    }
    var AddContact;
    var Pass = true;
    $("#ZXLXFSTD .GRZXInput").each(function () {
        if (!$.trim($(this).val())) {
            var Select = $(this).prev();
            var nextSpan = $(this).next();
            AddContact = Select.val() + ":" + $(this).val() + ";";
            nextSpan.removeClass("note").removeClass("success").addClass("error");
            nextSpan.html("<span>&nbsp;</span>请输入在线联系方式");
            Pass = false;
            return;
        }
    });
    if (!Pass)
        return;
    var AddSex = $("#ctl00_ContentPlaceHolder1_rblSex").val();
    var ProvID = $("#ctl00_ContentPlaceHolder1_drpAddProv").val();
    var CityID = $("#ctl00_ContentPlaceHolder1_drpAddCity").val();
    var RegionID = $("#ctl00_ContentPlaceHolder1_drpAddRegion").val();
    var AddCode = $("#txtCode").val();
    var IsRank = $("#cbIsRank").attr("checked");
    var OpeateID = $("#hidOpeateID").val();
    $.post("PSDZ.aspx", { OpeateID: OpeateID, Check: Save, ProvID: ProvID, CityID: CityID, RegionID: RegionID, UserName: encodeURIComponent(AddUserName), Phone: AddPhone, Telphone: AddTelPhone, Address: encodeURIComponent(AddAddress), Contact: encodeURIComponent(AddContact), IsRank: IsRank, Email: AddCode, Sex: AddSex, CompanyName: AddCompanyName }, function (result) {
        $('#AddPSDZDIV').unblock();
        $("#hidOpeateID").val('');
        if (result == "success") {
            alert('保存成功');
            reload();
        }
        else {
            alert('保存失败');
        }
    });

});


$(".rc1_tab1tit>tbody>tr").mousemove(function () {
    $(this).find(".SetRank").show();
}).mouseleave(function () {
    $(this).find(".SetRank").hide();
})


$(".EditPSDZ").bind("click", function () {
    $("#add").click();
    $('#AddPSDZDIV').block({ message: '<img alt="加载中" src="/images/Loading/Uploader.gif" />', css: { border: 'none', backgroundColor: 'transparent'} });
    $("#AddPSDZDIV").dialog('open');
    var OpeateID = $("#hidOpeateID");
    OpeateID.val($(this).attr("id"));
    var ParentTR = $(this).parent().parent();
    var UserNametd = ParentTR.find(".UserName").text().trim();
    var Regiontd = ParentTR.find(".Region").children().text().trim();
    var Addresstd = ParentTR.find(".Address").text().trim();
    var Email = ParentTR.find(".Email").text().trim();
    var Phonetd = ParentTR.find(".Phone").text().trim();
    var Contact = ParentTR.find(".Contact").text().trim();
    var Sex = ParentTR.find(".Sex").text().trim();
    var CompanyName = ParentTR.find(".CompanyName");
    if (CompanyName[0])
        CompanyName = CompanyName.text().trim();
    else
        CompanyName = "";

    var txtAddUserName = $("#txtAddUserName");
    var rblSex = $("#ctl00_ContentPlaceHolder1_rblSex");
    var txtPhone = $("#txtPhone");
    var txtTelphone = $("#txtTelphone");

    var drpAddProv = $("#ctl00_ContentPlaceHolder1_drpAddProv");
    var drpAddCity = $("#ctl00_ContentPlaceHolder1_drpAddCity");
    var drpAddRegion = $("#ctl00_ContentPlaceHolder1_drpAddRegion");
    var txtAddress = $("#txtAddress");
    var txtEmail = $("#txtCode");
    var ZXLXFSTD = $("#ZXLXFSTD");
    var AddHtml = $(".ZXLXFS").html();

    var GRZXInputCount = ZXLXFSTD.children(".GRZXInput").length;
    var Contacts = Contact.split(";");
    for (i = 1; i < Contacts.length - GRZXInputCount; i++) {
        $("#ZXLXFSTD").append('<div class="ZXLXFS">' + AddHtml + '</div><span class="colf2 DelZXLXFS" style="display: block; padding-top:2px; cursor: pointer">删除</span>');
    }
    $("#ZXLXFSTD .GRZXInput").each(function (i) {
        var Select = $(this).prev();
        var Values = Contacts[i].split(":");
        Select.val(Values[0])
        $(this).val(Values[1]);
    });

    var AddCompanyName =


    txtAddUserName.val(UserNametd);
    var Phonetds = Phonetd.split('/');
    txtPhone.val(Phonetds[0].replace("暂无", ""));
    txtTelphone.val(Phonetds[1].replace("暂无", ""));
    txtAddress.val(Addresstd);
    txtEmail.val(Email);
    var Regions = Regiontd.split("_");
    drpAddProv.val(Regions[0]);
    $.getJSON("PSDZ.aspx", { Check: "GetCity", ProID: Regions[0] }, function (result) {
        drpAddCity.html('');
        $.each(result, function (i, field) {
            drpAddCity.append("<option value=\"" + field.value + "\" >" + field.text + "</option>");
        });
        drpAddCity.val(Regions[1]);
        $.getJSON("PSDZ.aspx", { Check: "GetRegion", CityID: Regions[1] }, function (result) {
            drpAddRegion.html('');
            $.each(result, function (i, field) {
                drpAddRegion.append("<option value=\"" + field.value + "\" >" + field.text + "</option>");
            });
            drpAddRegion.val(Regions[2]);
            $('#AddPSDZDIV').unblock();
        });
    });
});